#! /bin/sh

set -e

if [ -n "$INITRD" ] && [ "$INITRD" = 'No' ]; then
    exit 0
fi
version="$1"
vmlinuz_location="$2"

# Note we only trigger on a remove, and not again on purge
if [ -n "$DEB_MAINT_PARAMS" ]; then
    eval set -- "$DEB_MAINT_PARAMS"
    case "$1" in
        remove)
            : echo nop
            ;;
        *)
            exit 0;
    esac
fi

# passing the kernel version is required
[ -z "$version" ] && exit 1

boot='/boot'
if [  -n "$vmlinuz_location" ]; then
    # Where is the image located? We'll place the initrd there.
    boot=$(dirname "$vmlinuz_location")
    bootarg="-b $boot"
fi

# try and remove the initramfs, and do not care if it fails
if [ -e "$boot/initrd.img-$version" ]; then
   rm -f "$boot/initrd.img-$version"  || true
fi
